import os
import urllib
import firedrake
import numpy as np
/home/firedrake/firedrake/lib/python3.10/site-packages/pytools/__init__.py:2428: UserWarning: unable to find git revision
warn("unable to find git revision")
/home/firedrake/firedrake/src/loopy/loopy/schedule/__init__.py:2201: UserWarning: pytools.persistent_dict 'loopy-schedule-cache-v4-2024.1-islpy2024.1-cgen2020.1-967461ba9c3677ee6f0334b9ee95ef0f0e51d208-v1': enabling safe_sync as default. This provides strong protection against data loss, but can be unnecessarily expensive for use cases such as caches.Pass 'safe_sync=False' if occasional data loss is tolerable. Pass 'safe_sync=True' to suppress this warning.
schedule_cache = WriteOncePersistentDict(
/home/firedrake/firedrake/src/loopy/loopy/tools.py:914: UserWarning: pytools.persistent_dict 'loopy-memoize-cache-buffer_array-LoopyKeyBuilder.LoopyKeyBuilder-v0-2024.1-islpy2024.1-cgen2020.1-967461ba9c3677ee6f0334b9ee95ef0f0e51d208-v1': enabling safe_sync as default. This provides strong protection against data loss, but can be unnecessarily expensive for use cases such as caches.Pass 'safe_sync=False' if occasional data loss is tolerable. Pass 'safe_sync=True' to suppress this warning.
transform_cache = WriteOncePersistentDict(
/home/firedrake/firedrake/src/loopy/loopy/tools.py:914: UserWarning: pytools.persistent_dict 'loopy-memoize-cache-preprocess_program-LoopyKeyBuilder.LoopyKeyBuilder-v0-2024.1-islpy2024.1-cgen2020.1-967461ba9c3677ee6f0334b9ee95ef0f0e51d208-v1': enabling safe_sync as default. This provides strong protection against data loss, but can be unnecessarily expensive for use cases such as caches.Pass 'safe_sync=False' if occasional data loss is tolerable. Pass 'safe_sync=True' to suppress this warning.
transform_cache = WriteOncePersistentDict(
/home/firedrake/firedrake/src/loopy/loopy/codegen/__init__.py:313: UserWarning: pytools.persistent_dict 'loopy-code-gen-cache-v3-2024.1-islpy2024.1-cgen2020.1-967461ba9c3677ee6f0334b9ee95ef0f0e51d208-v1': enabling safe_sync as default. This provides strong protection against data loss, but can be unnecessarily expensive for use cases such as caches.Pass 'safe_sync=False' if occasional data loss is tolerable. Pass 'safe_sync=True' to suppress this warning.
code_gen_cache = WriteOncePersistentDict(
/home/firedrake/firedrake/src/loopy/loopy/target/execution.py:724: UserWarning: pytools.persistent_dict 'loopy-typed-and-scheduled-cache-v1-2024.1-islpy2024.1-cgen2020.1-967461ba9c3677ee6f0334b9ee95ef0f0e51d208-v1': enabling safe_sync as default. This provides strong protection against data loss, but can be unnecessarily expensive for use cases such as caches.Pass 'safe_sync=False' if occasional data loss is tolerable. Pass 'safe_sync=True' to suppress this warning.
typed_and_scheduled_cache = WriteOncePersistentDict(
/home/firedrake/firedrake/src/loopy/loopy/target/execution.py:732: UserWarning: pytools.persistent_dict 'loopy-invoker-cache-v10-2024.1-islpy2024.1-cgen2020.1-967461ba9c3677ee6f0334b9ee95ef0f0e51d208-v1': enabling safe_sync as default. This provides strong protection against data loss, but can be unnecessarily expensive for use cases such as caches.Pass 'safe_sync=False' if occasional data loss is tolerable. Pass 'safe_sync=True' to suppress this warning.
invoker_cache = WriteOncePersistentDict(
import viskex
Read in and plot mesh
msh_filename = "data/garda.msh"
if not os.path.isfile(msh_filename):
os.makedirs("data", exist_ok=True)
msh_url = (
"https://raw.githubusercontent.com/FEMlium/FEMlium/main/"
"tutorials/01_introduction/data/garda.msh")
with urllib.request.urlopen(msh_url) as response, open(msh_filename, "wb") as msh_file:
msh_file.write(response.read())
mesh = firedrake.Mesh("data/garda.msh")
viskex.firedrake.plot_mesh(mesh)
viskex.firedrake.plot_mesh(mesh, dim=2)
viskex.firedrake.plot_mesh(mesh, dim=1)
viskex.firedrake.plot_mesh(mesh, dim=0)
Plot subdomains
viskex.firedrake.plot_mesh_sets(mesh, 2, "subdomains")
Plot boundaries
viskex.firedrake.plot_mesh_sets(mesh, 1, "boundaries")
Plot a scalar field
scalar_function_space = firedrake.FunctionSpace(mesh, "CG", 2)
x = firedrake.SpatialCoordinate(mesh)
if np.issubdtype(mesh.coordinates.dat.data_ro.dtype, np.complexfloating):
x = firedrake.real(x)
centroid = np.array([631544.0, 5054515.0])
rho = firedrake.sqrt((x[0] - centroid[0])**2 + (x[1] - centroid[1])**2)
theta = firedrake.atan2(x[1] - centroid[1], x[0] - centroid[0])
scalar_field = firedrake.interpolate(rho / firedrake.sqrt(1 - 0.5 * firedrake.cos(theta)**2), scalar_function_space)
viskex.firedrake.plot_scalar_field(scalar_field, "scalar")
Plot a vector field
vector_function_space = firedrake.VectorFunctionSpace(mesh, "CG", 2)
vector_field = firedrake.interpolate(
firedrake.as_vector((- rho * firedrake.sin(theta), rho * firedrake.cos(theta))), vector_function_space)
viskex.firedrake.plot_vector_field(vector_field, "vector")
viskex.firedrake.plot_vector_field(vector_field, "vector", glyph_factor=0.1)